package zuoye_4_14;

import java.util.concurrent.ArrayBlockingQueue;

public class Cooker extends Thread {
	private ArrayBlockingQueue<String> abq;
	private static final int PRODUCE_SIZE = 5;
	
	public Cooker(ArrayBlockingQueue<String> abq) {
		super();
		this.abq = abq;
	}

	@Override
	public void run() {
		while(true){
			try {
				synchronized(abq) {
					while(abq.size() >= PRODUCE_SIZE) {
						abq.wait();
					}
					for(int i = 0; i < PRODUCE_SIZE; i++) {
						Cooker.sleep(500);
						abq.put("产品");
						System.out.println("生产了"+"1个"+"产品");
					}
					abq.notifyAll();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		
		}
	}
}
